﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1.Test
{
    /// <summary>
    /// 实现加减和乘法运算，坐标点的移动和旋转
    /// 原点左上角，x：左-》右    y：上-》下  angle：右手定则，顺时针为+
    /// </summary>
    public class MyNumerics
    {
        public PointF moveByAngle(float distance, float angle,in PointF startPoint)
        {
            PointF res;
            angle = (float)(angle / 180 * Math.PI);
            float dis_x = 0.0f, dis_y = 0.0f;
            dis_x = distance * (float)Math.Cos(angle);
            dis_y = distance * (float)Math.Sin(angle);
            res = new PointF(startPoint.X + dis_x, startPoint.Y + dis_y);
            return res;
        }
        public PointF moveByX(float distance, in PointF startPoint)
        {
            PointF res = new PointF(startPoint.X+distance,startPoint.Y);
            return res;
        }
        public PointF moveByY(float distance, in PointF startPoint)
        {
            PointF res = new PointF( startPoint.X, startPoint.Y + distance);
            return res;
        }

        /// <summary>
        /// 旋转变换
        /// </summary>
        /// <param name="angle">旋转角度</param>
        /// <param name="startPoint">输入点</param>
        /// <param name="originPoint">旋转中心</param>
        /// <returns>结果</returns>
        public PointF rotate(float angle, in PointF startPoint,in PointF originPoint)
        {
            PointF res,p;
            p = new PointF(startPoint.X - originPoint.X, startPoint.Y - originPoint.Y);
            angle = (float)(angle / 180 * Math.PI);

            float x = p.X, y = p.Y;
            float x1 = (float)Math.Cos(angle) * x - (float)Math.Sin(angle) * y;
            float y1 = (float)Math.Cos(angle) * y + (float)Math.Sin(angle) * x;

            res = new PointF(x1 + originPoint.X, y1 + originPoint.Y);
            return res;
        }
    }
}
